import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
# 配置Chrome选项
chrome_options = Options()
chrome_options.add_argument('--user-data-dir=D:\\cxs\\chromedata')
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920x1080")
# 结束不退出
chrome_options.add_experimental_option("detach", True)

# 设置WebDriver路径（请根据实际情况修改路径）
# webdriver_service = Service(r'D:\chromedriver.exe')
webdriver_service = Service(ChromeDriverManager().install())

# 初始化WebDriver
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)

try:
    # 访问网页
    driver.get('https://guba.eastmoney.com/news,gmxx,1515181967.html')
    time.sleep(0.1)
    imgs = driver.find_elements(By.XPATH,'/ html / body / div[5] / img[1]')
    print("++++++++++++++++++++++++++++")
    print(driver.page_source)
    print("++++++++++++++++++++++++++++")
    if len(imgs)>0:
        imgs[0].click()
    lis = driver.find_elements(By.CLASS_NAME,'recont_right')
    for d in lis:
        ls = d.find_elements(By.TAG_NAME,'div')
        for d1 in ls:
            print(d1.text)
except Exception as e:
    print(e)